package com.myfojing.foshuoliaozhibingjing;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.List;


public class SpeakerListAdapter extends ArrayAdapter<Speaker> {
    private Context context;
    private List<Speaker> list;

    public SpeakerListAdapter(Context context, int resourceId, List<Speaker> list) {
        super(context, resourceId, list);

        this.context = context;
        this.list = list;
    }

    private static class ViewHolder {
        RadioButton speaker_sel;
        ImageView speaker_avatar;
        TextView speaker_name;
        ImageButton btn_preview;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        ViewHolder viewHolder;

        if (convertView == null) {
            convertView = ((Activity)context).getLayoutInflater().inflate(R.layout.list_speaker, null);

            viewHolder = new ViewHolder();
            viewHolder.speaker_sel = (RadioButton) convertView.findViewById(R.id.speaker_sel);
            viewHolder.speaker_avatar = (ImageView) convertView.findViewById(R.id.speaker_avatar);
            viewHolder.speaker_name = (TextView) convertView.findViewById(R.id.speaker_name);
            viewHolder.btn_preview = (ImageButton) convertView.findViewById(R.id.btn_preview);

            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        return convertView;
    }
}
